<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class CategoryRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $editRules = [
            'id'        => 'required|numeric',
            'name'      => 'required',
            'code'      => 'required',
            'sort'      => 'required|numeric',
            'status'    => 'required|boolean',
            'hot'       => 'required|boolean',
            'recommend' => 'required|boolean',
            'upid'      => 'sometimes|numeric',
        ];
        $createRules = [
            'name'      => 'required',
            'code'      => 'required',
            'sort'      => 'required|numeric',
            'status'    => 'required|boolean',
            'hot'       => 'required|boolean',
            'recommend' => 'required|boolean',
            'upid'      => 'sometimes|numeric',
        ];
        $data = Request::all();
        if($data['formType'] == 'edit'){
            return $editRules;
        }
        if($data['formType']== 'create')
        {
            return $createRules;
        }
    }
    public function attributes()
    {
        $attributes = array(
            'name'      => '行业分类名称',
            'code'      => 'code',
            'sort'      => '排序',
            'status'    => '状态（启用或禁用）',
            'hot'       => '是否热门',
            'recommend' => '是否推荐',
            'upid'      => '父分类',
        );
        return $attributes;
    }
    public function messages()
    {
        $messages = [
            'required'          => ':attribute为必填选项',
            'numeric'           => ':attribute必须为数字',
            'status.boolean'    => ':attribute必须为启用、暂不启用中的一种',
            'hot.boolean'       => ':attribute必须为热门、不热门中的一种',
            'recommend.boolean' => ':attribute必须为推荐、不推荐中的一种',
        ];

        return $messages;
    }
}
